﻿using shop.Areas.Main.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace shop.Areas.Main.Controllers
{
    public class CartController : Controller
    {
        //
        // GET: /Cart/

        Product product = new Product();
        public ActionResult Cart()
        {
            if (Session["username"] == null)
            {
                Session["name"] = "";
                Session["email"] = "";
                Session["adress"] = "";
                Session["phone"] = "";
            }
            return View();
        }
        public ActionResult Addtocart(int idnum, string name, string image, int qty, decimal price, string mau, string size)
        {
            product.ProductID = idnum;
            product.ProductName = name;
            product.Image = image;
            product.Quantity = qty;
            product.Price = price;
            product.mau = mau;
            product.size = size;
            ShoppingCart.Instance.AddProduct(product);
            return RedirectToAction("Cart", "Cart");
        }
        public ActionResult Update(int idnum, int qty)
        {
            if (qty >= 1)
            {
                ShoppingCart.Instance.UpdateProduct(idnum, qty);
            }
            else
            {
                ShoppingCart.Instance.UpdateProduct(idnum, 1);
            }
            return RedirectToAction("Cart", "Cart");
        }
        public ActionResult Delete(int idnum)
        {
            ShoppingCart.Instance.RemoveProduct(idnum);
            return RedirectToAction("Cart", "Cart");
        }
        public ActionResult Clear()
        {
            ShoppingCart.Instance.Clear();
            return RedirectToAction("Cart", "Cart");
        }
    }
}
